package com.javaweb.servlet.bean;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;

public class User implements HttpSessionBindingListener {
    private String username;
    private String password;

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public User() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public void valueBound(HttpSessionBindingEvent event) {
        ServletContext application=event.getSession().getServletContext();
        Object logincount=application.getAttribute("logincount");
        if (logincount==null) {
            application.setAttribute("logincount",1);
        }else {
            int count01=(Integer)logincount;
            count01++;
            application.setAttribute("logincount",count01);
        }
    }

    @Override
    public void valueUnbound(HttpSessionBindingEvent event) {
        ServletContext application=event.getSession().getServletContext();
        Integer logincount=(Integer) application.getAttribute("logincount");
        logincount--;
        application.setAttribute("logincount",logincount);

    }
}
